{extend name="public/base" /}
{block name="title"}文章管理{/block}
{block name="css"}
<link rel="stylesheet" href="__PUBLIC__/static/inspinia/css/plugins/datapicker/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="__PUBLIC__/static/inspinia/css/plugins/bootstrap-table/bootstrap-table.min.css">
<!-- ladda   -->
<link href="__PUBLIC__/static/inspinia/css/plugins/ladda/ladda-themeless.min.css" rel="stylesheet">
{/block}
{block name="main"}

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>文章列表 </h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-wrench"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li><a href="{:url(request()->controller().'/addArticle')}">新增文章</a></li>
                    </ul>
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <div class="ibox-content" style="padding:10px">
                <div class="row">
                    <div class="col-lg-4 col-md-12">
                        <a class="btn btn-sm btn-primary J_addMenuTab" href="{:url(request()->controller().'/addArticle')}">新增文章</a>
                        <div class="btn-group">
                            <button data-toggle="dropdown" class="btn btn-success btn-sm dropdown-toggle">
                                <i class="fa fa-check"></i>发布操作<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li><a href="javascript:void(0)" class="ajax-batch-set" data-action="{:url(request()->controller().'/postArticle')}">立即发布</a></li>
                                <li><a href="javascript:void(0)" class="ajax-batch-set" data-action="{:url(request()->controller().'/auditFirst')}">初审</a></li>
                                <li><a href="javascript:void(0)" class="ajax-batch-set" data-action="{:url(request()->controller().'/auditSecond')}">终审</a></li>
                            </ul>
                        </div>

                        <div data-toggle="buttons" class="btn-group">
                            <label class="ladda-button btn btn-sm btn-warning ajax-batch-set" data-style="zoom-in" data-action="{:url('Article/setTop')}"> <i class="fa fa-arrow-circle-up"></i> 置顶 </label>
                            <label class="ladda-button btn btn-sm btn-info" data-style="zoom-in" data-action="{:url('Article/setTimingPost')}" onclick="showTimingPostModel(this)"> <i class="fa fa-clock-o"></i> 定时发布 </label>
                            <label class="ladda-button btn btn-sm btn-danger ajax-batch-set-prompt" data-style="zoom-in" data-title="提示" data-text="确认要批量删除文章吗？" data-action="{:url('Article/deleteArticle')}"> <i class="fa fa-trash"></i> 删除 </label>
                        </div>
                    </div>
                    <div class="col-lg-8 col-md-12 text-right">
                        <form method="get" role="form" class="form-inline">
                            <div class="form-group">
                                <input type="text" name="key" placeholder="关键字" class="form-control m-b-xs" value="{$Think.get.key|default=''}">
                            </div>
                            <div class="form-group">
                                <select name="status" class="form-control m-b-xs">
                                    <option value="">文章状态</option>
                                    <option value="0" {heq name="Think.get.status" value="0"}selected{/heq}>草稿</option>
                                    {if get_config('article_audit_switch') == 'true'}
                                    <option value="1" {heq name="Think.get.status" value="1"}selected{/heq}>申请发布</option>
                                    <option value="2" {heq name="Think.get.status" value="2"}selected{/heq}>初审拒绝</option>
                                    <option value="3" {heq name="Think.get.status" value="3"}selected{/heq}>初审通过</option>
                                    <option value="4" {heq name="Think.get.status" value="4"}selected{/heq}>终审拒绝</option>
                                    {/if}
                                    <option value="5" {heq name="Think.get.status" value="5"}selected{/heq}>已发布</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <select name="categoryId" class="form-control m-b-xs">
                                    <option value="-1">不限分类</option>
                                    {volist name="categoryList" id="vo"}
                                    <option value="{$vo.id}" {notempty name="Think.get.categoryId"}{eq name="Think.get.categoryId" value="$vo['id']"}selected{/eq}{/notempty}>{$vo._name|raw}</option>
                                    {/volist}
                                </select>
                            </div>
                            <div class="form-group">
                                <input type="text" autocomplete="off" class="form-control m-b-xs form-datetime" placeholder="起始日期" id="queryDate" name="startTime" value="{$Think.get.startTime |default=$startTime}">
                            </div>
                            <div class="form-group">
                                <input type="text" autocomplete="off" class="form-control m-b-xs form-datetime" placeholder="终止日期" name="endTime" value="{$Think.get.endTime |default=$endTime}">
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-primary m-b-xs">查找</button>
                            </div>

                        </form>
                    </div>
                </div>

                <div class="table-responsive bootstrap-table" style="padding-bottom:80px">
                    <div class="fixed-table-container">
                        <table class="table table-bordered table-hover table-striped table-condensed">
                            <thead>
                            <tr>
                                <th><div class="th-inner"><input type="checkbox" class="ajax-check-all" id="0"></div></th>
                                <th><div class="th-inner">ID</div></th>
                                <th><div class="th-inner">所属分类</div></th>
                                <th><div class="th-inner">标题</div></th>
                                <th><div class="th-inner">状态</div></th>
                                <th><div class="th-inner">浏览量</div></th>
                                <th><div class="th-inner">索引(？)</div></th>
                                <th data-field="post_time"><div class="th-inner sortable both {$sortedFields.post_time}">发布时间</div></th>
                                <th data-field="create_time"><div class="th-inner sortable both {$sortedFields.create_time}">创建时间</div></th>
                                <th><div class="th-inner">操作</div></th>
                            </tr>
                            </thead>
                            {foreach name="list" item="vo"}
                            <tr>
                                <td><input type="checkbox" class="ajax-check" value="{$vo.id}"></td>
                                <td>{$vo.id}</td>
                                <td>
                                    {volist name="vo.categorys" id="categoryVo" empty="未分类"}
                                    {gt name="key" value="0"}<br>{/gt}<span class="label">{$categoryVo.title_cn}</span>
                                    {/volist}
                                </td>
                                <td><a href="{:url(request()->controller().'/viewArticle',['id'=>$vo['id']])}">{$vo.title}</a>
                                    {if $vo.thumb_image_id > 0}<i class="fa fa-picture-o"></i>{/if}
                                    {eq name="vo.is_top" value="1"}<span class="label label-info label-sm">顶</span>{/eq}
                                </td>
                                <td>{$vo.status_text}</td>
                                <td align="center">{$vo.read_count}</td>
                                <td align="center">
                                    <a href="https://www.baidu.com/s?wd={:url('cms/Article/viewArticle', ['aid'=>$vo.id], true, get_config('domain_name'))}" target="_blank">
                                        {php}$index = $vo->meta('baidu_index');{/php}
                                        {:$index != true ? '否': '是'}
                                    </a>
                                </td>
                                <td>{if $vo.status == \app\common\model\ArticleModel::STATUS_PUBLISHED}
                                    {$vo.post_time}
                                    {else /}
                                    {notempty name="$vo.timing"}{$vo.timing}<i class="fa fa-clock-o"></i>{/notempty}
                                    {/if}
                                </td>
                                <td>{$vo.create_time}</td>
                                <td>
                                    <a href="{:url(request()->controller().'/viewArticle',['id'=>$vo['id']])}" class="J_addMenuTab" data-menu-name="查看文章"><button class="btn btn-xs btn-info" data-toggle="tooltip" data-placement="top" title="查看"><i class="fa fa-eye"></i> 查看</button></a>
                                    <a href="{:url(request()->controller().'/editArticle',['id'=>$vo['id']])}"><button class="btn btn-xs btn-warning" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-pencil"></i> 修改</button></a>

                                    <div class="btn-group">
                                        <button data-toggle="dropdown" class="btn btn-success btn-xs dropdown-toggle">
                                            {$vo.status_text}<span class="caret"></span>
                                        </button>

                                        <ul class="dropdown-menu">
                                            {eq name="vo.status" value="0"}
                                            <li>
                                                <a href="{:url(request()->controller().'/postArticle',['id'=>$vo['id']])}" class="ajax-a" style="color: black">立即发布</a>
                                            </li>
                                            {/eq}
                                            <li>
                                                {if $vo.status == 1}
                                                <a href="{:url(request()->controller().'/auditFirst',['id'=>$vo['id']])}" class="ajax-a" style="color: black">初审</a>
                                                {elseif $vo.status >= 3/}
                                                <a class="firstTrial">已初审</a>
                                                {else /}
                                                <a class="trial">初审</a>
                                                {/if}
                                            </li>
                                            <li class="divider"></li>
                                            <li>
                                                {if $vo.status == 3}
                                                <a href="{:url(request()->controller().'/auditSecond',['id'=>$vo['id']])}" class="ajax-a" style="color: black">终审</a>
                                                {elseif $vo.status >= 5/}
                                                <a class="secondTrial">已终审</a>
                                                {else /}
                                                <a class="trial">终审</a>
                                                {/if}
                                            </li>
                                        </ul>
                                    </div>

                                    {eq name="vo.is_top" value="0"}
                                    <button class="btn btn-xs btn-info ajax-btn" data-action="{:url(request()->controller().'/setTop',['id'=>$vo['id']])}"><i class="fa fa-arrow-circle-up"></i> 置顶</button>
                                    {else/}
                                    <button class="btn btn-xs btn-white ajax-btn" data-action="{:url(request()->controller().'/unsetTop',['id'=>$vo['id']])}"><i class="fa fa-arrow-circle-down"></i> 取消置顶</button>
                                    {/eq}
                                    <button class="btn btn-xs btn-danger ajax-btn-warning" data-action="{:url('Article/deleteArticle',['id'=>$vo['id']])}" data-title="提示" data-text="您确认要删除文章吗"><i class="fa fa-remove"></i> 删除</button>
                                    {if condition="$vo.status >= 0 &&  $vo.status < 5"}
                                    <button class="btn btn-xs btn-info" onclick="showTimingPostModel(this)" data-id="{$vo['id']}"><i class="fa fa-clock-o"></i>定时发布</button>
                                    {/if}
                                </td>
                            </tr>
                            {/foreach}

                        </table>
                    </div>

                    {$pages|raw}
                </div>

            </div>
        </div>
    </div>
</div>

{include file="public/modals" /}

<!-- 定时设置模态框开始 -->
<div class="modal fade" id="timingPostModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    设定发布时间
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal ajax-form" action="{:url('Article/setTimingPost')}" method="post">
                    <input type="hidden" name="id" value="">
                    <div class="form-group">
                        <label class="col-lg-2 control-label">选择时间:</label>
                        <div class="col-lg-10">
                            <input type="text" name="postTime" autocomplete="off" placeholder="点击输入框选择" class="form-datetime-timing form-control" readonly>
                            <span class="help-block m-b-none"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-10">
                            <button class="btn btn-sm btn-white" type="submit">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 定时设置模态框结束 -->

{/block}

{block name="js"}
<!--日期选择器-->
<script src="__PUBLIC__/static/inspinia/js/plugins/datapicker/bootstrap-datetimepicker.min.js"></script>
<script src="__PUBLIC__/static/inspinia/js/plugins/datapicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>

<script src="__PUBLIC__/static/inspinia/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<!-- Ladda -->
<script src="__PUBLIC__/static/inspinia/js/plugins/ladda/spin.min.js"></script>
<script src="__PUBLIC__/static/inspinia/js/plugins/ladda/ladda.min.js"></script>
<script src="__PUBLIC__/static/inspinia/js/plugins/ladda/ladda.jquery.min.js"></script>

<script src="__PUBLIC__/static/inspinia/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script>
    // 排序
    $(function() {
        //批量操作 审核,取消审核,删除
        var laddaBtn = $('.ajax-batch-set').ladda();
        laddaBtn.click(function() {
            // Start loading
            $(this).ladda('start');

            var ids = getAjaxCheckedValues();
            if (!ids) {
                layer.msg('请选择要操作的文章!', function(){});
                $(this).ladda('stop');
                return;
            }
            var action = $(this).data('action');
            $.each(ids, function (i, id) {
                $.post(action, {id: id}, function (data) {
                    //console.log(data);
                    if (data.code == 0 && ids.length == 1) {
                        layer.msg(data.msg, function(){});
                        location.reload();
                        return false;
                    }
                });
            });

            setTimeout(function () {
                location.reload();
            }, 800);
        });

        //删除前提示
        $('.ajax-batch-set-prompt').click(function() {
            var title = $(this).data('title') != undefined ? $(this).data('title') : '提示';
            var text = $(this).data('text') != undefined ? $(this).data('text') : '确认要执行此操作吗?';

            layer.confirm(text, {
                title: title,
                btn: ['确认', '取消']
            }, function() {
                layer.closeAll('dialog');

                var laddaBtn = $('.ajax-batch-set-prompt').ladda();

                // Start loading
                $(laddaBtn).ladda('start');

                var ids = getAjaxCheckedValues();
                if (!ids) {
                    layer.msg('请选择要操作的文章!', function(){});
                    $(laddaBtn).ladda('stop');
                    return;
                }
                var action = $(laddaBtn).data('action');
                $.post(action, {id: ids.join(',')}, function (data) {
                    //console.log(data);
                    if (data.code == 0 && ids.length == 1) {
                        layer.msg(data.msg, function(){});
                        location.reload();
                        return false;
                    }
                });

                setTimeout(function () {
                    location.reload();
                }, 800);

            }, function () {
                layer.closeAll('dialog');
            });

        });


        $(".bootstrap-table").on('click', 'div.sortable', function(event) {
            event.preventDefault();
            /* Act on the event */
            // 获取排序方式
            var field = $(this).parent().data("field");
            var sort = "asc";
            // alert(field);return;
            if ($(this).hasClass("desc")) {
                $(this).removeClass("desc");
                $(this).addClass("asc");
                sort = "asc";
            } else if ($(this).hasClass("asc")) {
                $(this).removeClass("asc");
                $(this).addClass("desc");
                sort = "desc";
            } else {
                $(this).addClass("asc");
                sort = "asc";
            }

            //get的方式传参数到后台
            var url = window.location.href;
            url += (url.indexOf('?') < 0 ? '?' : '&') + "field=" + field + "&sort=" + sort;
            window.location.href = url;
        });
    });

    // 定时模态框
    function showTimingPostModel(obj) {
        if ($(obj).prop('tagName') == 'LABEL') {
            var ids = getAjaxCheckedValues();
            if (!ids) {
                layer.msg('请选择要操作的文章!', function(){});
                return;
            }

            $("input[name='id']").val(ids.join(','));
        } else {
            var aid = $(obj).data('id');
            $("input[name='id']").val(aid);
        }

        $('#timingPostModal').modal('show');
    }

    //日期控件（查询）
    $('.form-datetime').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd',
        startView: 'month',
        minView: 2,
        autoclose: true,
        todayBtn: true
    });

    //日期控件（定时器）
    $('.form-datetime-timing').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd hh:ii:ss',
        startView: 'month',
        minView: 0,
        autoclose: true,
        todayBtn: true
    });

    $('.addHeadline').click(function(e){
        e.preventDefault();
        var $adModal = $('#addAd');
        var _this = $(this);
        $adModal.find('input[name="title"]').val(_this.data('title'));
        $adModal.find('input[name="url"]').val(_this.data('url'));
        $adModal.find('input[name="artId"]').val(_this.data('articleId'));
        $adModal.modal('show');
    });


    //不可选取已审核文章状态
    $('.firstTrial').attr("disabled", true);
    $('.firstTrial').css("pointer-events", "none");

    $('.secondTrial').attr("disabled", true);
    $('.secondTrial').css("pointer-events", "none");

    $('.trial').attr("disabled", true);
    $('.trial').css("pointer-events", "none");

</script>
{/block}